﻿namespace HRM.CORE.Machine
{
    using APP.HELPER.Data.Helper;
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using System; using Extra.ERP;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmSelectField : XtraForm
    {
        private SimpleButton btnCancel;
        private SimpleButton btnOK;
        private CheckEdit checkEdit1;
        private GridColumn colFieldName;
        private GridColumn colSelectField;
        private IContainer components;
        private SqlDataAdapter da;
        private DataTable dt;
        private List<string> FieldName;
        private List<int> FieldNameIndex;
        private GridView gbList;
        private GridControl gcList;
        public GetListString get_;
        private DevExpress.Utils.ImageCollection imageCollection1;
        private LabelControl lcDescription;
        private int m_Type;
        private SqlHelper myHelp;
        private string[] ParamName;
        private RepositoryItemComboBox repSelectField;

        public xfmSelectField(List<string> fieldName, string[] paramName)
        {
            this.FieldNameIndex = new List<int>();
            this.FieldName = new List<string>();
            this.m_Type = 0;
            this.myHelp = new SqlHelper();
            this.dt = new DataTable();
            this.components = null;
            this.InitializeComponent();
            this.ParamName = paramName;
            this.FieldName = fieldName;
        }

        public xfmSelectField(List<string> fieldName, string[] paramName, int Type)
        {
            this.FieldNameIndex = new List<int>();
            this.FieldName = new List<string>();
            this.m_Type = 0;
            this.myHelp = new SqlHelper();
            this.dt = new DataTable();
            this.components = null;
            this.InitializeComponent();
            this.ParamName = paramName;
            this.FieldName = fieldName;
            this.m_Type = Type;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.gbList.RowCount; i++)
            {
                DataRow dataRow = this.gbList.GetDataRow(i);
                if (dataRow[1].ToString() != "")
                {
                    for (int j = 0; j < this.repSelectField.Items.Count; j++)
                    {
                        if (dataRow[1].ToString() == this.repSelectField.Items[j].ToString())
                        {
                            this.FieldNameIndex.Add(j);
                        }
                    }
                }
                else
                {
                    this.FieldNameIndex.Clear();
                    MessageBox.Show("vui l\x00f2ng chọn đậy đủ th\x00f4ng tin cho c\x00e1c trường!", "Lỗi");
                    break;
                }
            }
            if (this.FieldNameIndex.Count == 7)
            {
                this.get_(this.FieldNameIndex);
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            foreach (string str in this.FieldName)
            {
                if (str != "")
                {
                    this.da = new SqlDataAdapter("select N'" + str + "' as [FieldName], '' as [SelectField]", this.myHelp.ConnectionString);
                    this.da.Fill(this.dt);
                }
            }
            this.gcList.DataSource = this.dt;
            foreach (string str2 in this.ParamName)
            {
                if (str2 != "")
                {
                    this.repSelectField.Items.Add(str2);
                }
            }
            try
            {
                if (this.m_Type == 0)
                {
                    this.gbList.SetRowCellValue(0, this.colSelectField, this.ParamName[0]);
                    this.gbList.SetRowCellValue(1, this.colSelectField, this.ParamName[1]);
                    this.gbList.SetRowCellValue(2, this.colSelectField, this.ParamName[2]);
                    this.gbList.SetRowCellValue(3, this.colSelectField, this.ParamName[3]);
                    this.gbList.SetRowCellValue(4, this.colSelectField, this.ParamName[4]);
                    this.gbList.SetRowCellValue(5, this.colSelectField, this.ParamName[5]);
                    this.gbList.SetRowCellValue(6, this.colSelectField, this.ParamName[6]);
                }
                else if (this.m_Type == 1)
                {
                    this.gbList.SetRowCellValue(0, this.colSelectField, this.ParamName[2]);
                    this.gbList.SetRowCellValue(1, this.colSelectField, this.ParamName[4]);
                    this.gbList.SetRowCellValue(2, this.colSelectField, this.ParamName[4]);
                    this.gbList.SetRowCellValue(3, this.colSelectField, this.ParamName[8]);
                    this.gbList.SetRowCellValue(4, this.colSelectField, this.ParamName[8]);
                    this.gbList.SetRowCellValue(5, this.colSelectField, this.ParamName[6]);
                    this.gbList.SetRowCellValue(6, this.colSelectField, this.ParamName[1]);
                }
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmSelectField));
            this.gcList = new GridControl();
            this.gbList = new GridView();
            this.colFieldName = new GridColumn();
            this.colSelectField = new GridColumn();
            this.repSelectField = new RepositoryItemComboBox();
            this.btnOK = new SimpleButton();
            this.imageCollection1 = new DevExpress.Utils.ImageCollection(this.components);
            this.btnCancel = new SimpleButton();
            this.lcDescription = new LabelControl();
            this.checkEdit1 = new CheckEdit();
            this.gcList.BeginInit();
            this.gbList.BeginInit();
            this.repSelectField.BeginInit();
            this.imageCollection1.BeginInit();
            this.checkEdit1.Properties.BeginInit();
            base.SuspendLayout();
            this.gcList.Location = new Point(10, 60);
            this.gcList.MainView = this.gbList;
            this.gcList.Name = "gcList";
            this.gcList.RepositoryItems.AddRange(new RepositoryItem[] { this.repSelectField });
            this.gcList.Size = new Size(0x1a2, 0xe5);
            this.gcList.TabIndex = 3;
            this.gcList.ViewCollection.AddRange(new BaseView[] { this.gbList });
            this.gbList.Columns.AddRange(new GridColumn[] { this.colFieldName, this.colSelectField });
            this.gbList.GridControl = this.gcList;
            this.gbList.Name = "gbList";
            this.gbList.OptionsView.ColumnAutoWidth = false;
            this.gbList.OptionsView.ShowGroupPanel = false;
            this.gbList.OptionsView.ShowIndicator = false;
            this.colFieldName.Caption = "Mặc định";
            this.colFieldName.FieldName = "FieldName";
            this.colFieldName.Name = "colFieldName";
            this.colFieldName.OptionsColumn.AllowEdit = false;
            this.colFieldName.OptionsColumn.ReadOnly = true;
            this.colFieldName.Visible = true;
            this.colFieldName.VisibleIndex = 0;
            this.colFieldName.Width = 0x9f;
            this.colSelectField.Caption = "T\x00f9y chọn";
            this.colSelectField.ColumnEdit = this.repSelectField;
            this.colSelectField.FieldName = "SelectField";
            this.colSelectField.Name = "colSelectField";
            this.colSelectField.Visible = true;
            this.colSelectField.VisibleIndex = 1;
            this.colSelectField.Width = 0xc0;
            this.repSelectField.AutoHeight = false;
            this.repSelectField.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repSelectField.Name = "repSelectField";
            this.btnOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOK.ImageIndex = 2;
            this.btnOK.ImageList = this.imageCollection1;
            this.btnOK.Location = new Point(0xfb, 0x12e);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new Size(0x52, 0x17);
            this.btnOK.TabIndex = 4;
            this.btnOK.Text = "X\x00e1c Nhận";
            this.btnOK.Click += new EventHandler(this.btnOK_Click);
            this.imageCollection1.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection1.ImageStream");
            this.imageCollection1.Images.SetKeyName(0, "ico_alpha_Search_16x16.png");
            this.imageCollection1.Images.SetKeyName(1, "ico_alpha_Delete_16x16.png");
            this.imageCollection1.Images.SetKeyName(2, "document2.png");
            this.imageCollection1.Images.SetKeyName(3, "open-16x16.png");
            this.imageCollection1.Images.SetKeyName(4, "close.png");
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnCancel.ImageIndex = 4;
            this.btnCancel.ImageList = this.imageCollection1;
            this.btnCancel.Location = new Point(0x15a, 0x12e);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x52, 0x17);
            this.btnCancel.TabIndex = 5;
            this.btnCancel.Text = "Hủy";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.lcDescription.AllowHtmlString = true;
            this.lcDescription.Appearance.Options.UseTextOptions = true;
            this.lcDescription.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.lcDescription.AutoSizeMode = LabelAutoSizeMode.None;
            this.lcDescription.Location = new Point(12, 9);
            this.lcDescription.Name = "lcDescription";
            this.lcDescription.Size = new Size(0x1a2, 0x2a);
            this.lcDescription.TabIndex = 6;
            this.lcDescription.Text = "    Chọn trường dữ liệu tương ứng với cột thứ 1 ở cột thứ 2 để gh\x00e9p dữ liệu. C\x00f3 thể tham khảo tập tin mẫu trong ổ đĩa c\x00e0i đặt, chọn thư mục <color=blue><b>Import File</b></color>";
            this.checkEdit1.Enabled = false;
            this.checkEdit1.Location = new Point(10, 0x12e);
            this.checkEdit1.Name = "checkEdit1";
            this.checkEdit1.Properties.Caption = "Th\x00eam v\x00e0o danh s\x00e1ch đang hiển thị";
            this.checkEdit1.Size = new Size(0xeb, 0x13);
            this.checkEdit1.TabIndex = 7;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1b7, 0x150);
            base.Controls.Add(this.checkEdit1);
            base.Controls.Add(this.lcDescription);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOK);
            base.Controls.Add(this.gcList);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmSelectField";
            base.ShowIcon = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Gh\x00e9p Trường Dữ Liệu";
            base.Load += new EventHandler(this.xfmSelectField_Load);
            this.gcList.EndInit();
            this.gbList.EndInit();
            this.repSelectField.EndInit();
            this.imageCollection1.EndInit();
            this.checkEdit1.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void xfmSelectField_Load(object sender, EventArgs e)
        {
            this.Init();
        }

        public delegate List<int> GetListString(List<int> list_);
    }
}

